<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/19
 * Time: 9:09
 */

namespace app\ext\model;


class ArticleModel
{
    public function articleList($where = [], $start = 1, $limit = 10, $field = '*'){
        $where = array_merge($where,['is_delete'=>0]);
        $list = db('article')
            ->where($where)
            ->order('is_top desc,add_time desc')
            ->field($field)
            ->limit($limit)
            ->select();

        return $list;
    }

    public function articleDetail($id = 0)
    {
        return db('article')->where(['id'=>$id,'is_delete'=>0])->find();
    }

    public function cArticle($c_id = 0)
    {
        return db('article')->where(['c_id'=>$c_id,'is_delete'=>0])->count();
    }

    public function articleSave($data)
    {
        if(empty($data)) return false;
        return db('article')->insertGetId($data);
    }

    public function del($id = 0)
    {
        return db('article')->where(['id'=>$id])->delete();
    }
}